package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;
import model.Perspective;

@SuppressWarnings("serial")
public class Thumbnail extends BaseView
{
    private ImageIcon icon;
    private JLabel picLabel;
    
    private int THUMB_SIZE = 200;

    //Constructors
    public Thumbnail(Perspective p) {
    	perspective = p;
    }

    //operations
	protected void init()
    {   
        icon = new ImageIcon();
        picLabel = new JLabel("Apercu");
        picLabel.setHorizontalTextPosition(JLabel.CENTER);
        picLabel.setVerticalTextPosition(JLabel.TOP);
        setBackground(Color.LIGHT_GRAY);
        picLabel.setBorder(new LineBorder(Color.black));

        add(picLabel);
    }

	@Override
    protected void update(Perspective p) 
    {
        icon.setImage(p.getRawImage().getImage().getScaledInstance(THUMB_SIZE, -1, Image.SCALE_SMOOTH ));//-1 conserve le ratio de l'image
        
        picLabel.setIcon(icon);
        
        repaint();
    }
	
	
	public void paint(Graphics g) {
		super.paint(g);
		g.setColor(Color.GREEN);
		g.drawRect((int)(picLabel.getX() - perspective.getX() * THUMB_SIZE / perspective.getRawImage().getWidth() / perspective.getZoom()), 
				(int)(26 - perspective.getY() * THUMB_SIZE / perspective.getRawImage().getWidth() / perspective.getZoom()),
				(int)(this.getWidth() / perspective.getZoom() * THUMB_SIZE / perspective.getRawImage().getWidth()), 
				(int)(this.getHeight() / perspective.getZoom() * THUMB_SIZE / perspective.getRawImage().getWidth()));
	}
}
